package com.phone.handle;

import com.phone.entity.APP;
import com.phone.entity.Cash;
import com.phone.entity.User;
import com.phone.exception.ErrorOwneridException;
import com.phone.exception.NoBindingIdException;
import com.phone.exception.NotSufficientMoneyException;
import com.phone.utils.TextUtil;
import org.hibernate.Query;
import org.hibernate.Session;

import java.util.Date;
import java.util.List;

/**
 * Created by tisen on 2017/8/9.
 */
public class AppHandle extends EntityHandle<APP> {

    public AppHandle(Session session) {
        super(session);
    }


    public void update(String id, String name, String introduction, String icon_url, String file_url, String version) throws Exception {
        APP app = get(id);
        if (!TextUtil.textIsEmpty(name))
            app.setName(name);
        if (!TextUtil.textIsEmpty(introduction))
            app.setIntroduction(introduction);
        if (!TextUtil.textIsEmpty(icon_url))
            app.setIcon_url(icon_url);
        if (!TextUtil.textIsEmpty(file_url))
            app.setFile_url(file_url);
        if (!TextUtil.textIsEmpty(version))
            app.setVersion(version);
        if (TextUtil.textIsEmpty(name) && TextUtil.textIsEmpty(introduction) && TextUtil.textIsEmpty(icon_url) && TextUtil.textIsEmpty(file_url) && TextUtil.textIsEmpty(version)) {
        } else {
            app.setUpdate_time(new Date());
            session.update(app);
        }
    }

    @Override
    public boolean checkOwnerId(String ownerid) throws Exception {
        return true;
    }
}
